<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/1/19 0019
  Time: 15:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../basePath.jsp"%>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title>我的购物车</title>

    <link rel="stylesheet" type="text/css" href="${basePath}staticDwm/css/webbase.css" />
    <link rel="stylesheet" type="text/css" href="${basePath}staticDwm/css/pages-cart.css" />
</head>

<body>
<!--head-->
<div class="top">
    <div class="py-container">
        <div class="shortcut">
            <ul class="fl">
                <li class="f-item">亲爱的${user.username},品优购欢迎您！</li>
            </ul>
            <ul class="fr">
                <li class="f-item">我的订单</li>
                <li class="f-item space"></li>
                <li class="f-item">我的品优购</li>
                <li class="f-item space"></li>
                <li class="f-item">品优购会员</li>
                <li class="f-item space"></li>
                <li class="f-item">企业采购</li>
                <li class="f-item space"></li>
                <li class="f-item">关注品优购</li>
                <li class="f-item space"></li>
                <li class="f-item">客户服务</li>
                <li class="f-item space"></li>
                <li class="f-item">网站导航</li>
            </ul>
        </div>
    </div>
</div>
<div class="cart py-container">
    <!--logoArea-->
    <div class="logoArea">
        <div class="fl logo"><span class="title">购物车</span></div>
        <div class="fr search">
            <form class="sui-form form-inline">
                <div class="input-append">
                    <input type="text" type="text" class="input-error input-xxlarge" placeholder="品优购自营" />
                    <button class="sui-btn btn-xlarge btn-danger" type="button">搜索</button>
                </div>
            </form>
        </div>
    </div>
    <!--All goods-->
    <div class="allgoods">
        <h4>全部商品</h4>
        <div class="cart-main">
            <div class="yui3-g cart-th">
                <div class="yui3-u-1-4">全部</div>
                <div class="yui3-u-1-4">商品</div>
                <div class="yui3-u-1-8">单价（元）</div>
                <div class="yui3-u-1-8">数量</div>
                <div class="yui3-u-1-8">小计（元）</div>
                <div class="yui3-u-1-8">操作</div>
            </div>
            <div class="cart-item-list">
                <c:forEach items="${cartName}" var="cartName">
                    <div class="cart-shop">
                        <input type="checkbox" name="${cartName.catname}1" value="" onclick="qx('${cartName.catname}')"/>
                        <span class="shopname self">${cartName.catname}</span>
                        <c:forEach items="${carts}" var="Cart">
                            <c:if test="${cartName.catname eq Cart.catname}">
                                <c:if test="${Cart.state==1}">
                                    <div class="cart-body">
                                        <div class="cart-list">
                                            <ul class="goods-list yui3-g">
                                                <li class="yui3-u-1-24">
                                                    <input type="checkbox" name="${cartName.catname}" value="${Cart.id}" onclick="Statistics()"/>
                                                </li>
                                                <li class="yui3-u-11-24">
                                                    <div class="good-item">
                                                        <div class="item-img"><img src="${basePath}cart/showPic?pic=${Cart.pic}" /></div>
                                                        <div class="item-msg" >${Cart.content}</div>
                                                    </div>
                                                </li>

                                                <li class="yui3-u-1-8"><span class="price" id="${Cart.id}1">${Cart.price}</span></li>
                                                <li class="yui3-u-1-8">
<%--                                                    //<a href='javascript:void(0)' onclick=\"cc('" + parameter1 + "','" + parameter2 + "','" + parameter3 + "','" + parameter4 + "')\">我的链接</a>--%>
                                                    <a href="javascript:void(0);" onclick="jei(${Cart.id})" class="increment mins">-</a>
                                                    <input id="${Cart.id}2" readonly="readonly" autocomplete="off" type="text" value="${Cart.number}" minnum="1" class="itxt" />
                                                    <a href="javascript:void(0);" onclick="jia(${Cart.id})" class="increment plus">+</a>
                                                </li>
                                                <li class="yui3-u-1-8"><span id="${Cart.id}3" class="sum">${Cart.price*Cart.number}</span></li>
                                                <li class="yui3-u-1-8">
                                                    <a href="${basePath}cart/updateCartState?id=${Cart.id}&state=0&name=${user.username}">删除</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </c:if>
                            </c:if>
                        </c:forEach>
                    </div>
                </c:forEach>
            </div>
        </div>
        <div class="cart-tool">
            <div class="select-all">
                <input type="checkbox" name="qxx" onclick="qxx()"/>
                <span>全选</span>
            </div>
            <div class="option">
                <a href="javascript:void(0);" onclick="addUpdate()">删除选中的商品</a>
            </div>
            <div class="toolbar">
                <div class="chosed">已选择<span id="commodity">0</span>件商品</div>
                <div class="sumprice">
                    <span><em>总价（不含运费） ：</em><i class="summoney" id="and">¥0.00</i></span>
                </div>
                <div class="sumbtn">
                    <a class="sum-btn" href="javascript:void(0);" onclick="getOrderInfo()" target="_blank">结算</a>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="deled">
            <span>已删除商品，您可以重新购买或加关注：</span>
            <div class="cart-list del">
                <c:forEach items="${carts}" var="carts">
                    <c:if test="${carts.state==0}">
                        <ul class="goods-list yui3-g">
                            <li class="yui3-u-1-2">
                                <div class="good-item">
                                    <div class="item-msg">${carts.content}</div>
                                </div>
                            </li>
                            <li class="yui3-u-1-6"><span class="price">${carts.price}</span></li>
                            <li class="yui3-u-1-6">
                                <span class="number">${carts.number}</span>
                            </li>
                            <li class="yui3-u-1-8">
                                <a href="${basePath}cart/updateCartState?id=${carts.id}&state=1&name=${user.username}">重新购买</a>
                            </li>
                        </ul>
                    </c:if>
                </c:forEach>
            </div>
        </div>
    </div>
</div>
<!-- 底部栏位 -->
<!--页面底部-->
<div class="clearfix footer">
    <div class="py-container">
        <div class="footlink">
            <div class="Mod-service">
                <ul class="Mod-Service-list">
                    <li class="grid-service-item intro  intro1">

                        <i class="serivce-item fl"></i>
                        <div class="service-text">
                            <h4>正品保障</h4>
                            <p>正品保障，提供发票</p>
                        </div>

                    </li>
                    <li class="grid-service-item  intro intro2">

                        <i class="serivce-item fl"></i>
                        <div class="service-text">
                            <h4>正品保障</h4>
                            <p>正品保障，提供发票</p>
                        </div>

                    </li>
                    <li class="grid-service-item intro  intro3">

                        <i class="serivce-item fl"></i>
                        <div class="service-text">
                            <h4>正品保障</h4>
                            <p>正品保障，提供发票</p>
                        </div>

                    </li>
                    <li class="grid-service-item  intro intro4">

                        <i class="serivce-item fl"></i>
                        <div class="service-text">
                            <h4>正品保障</h4>
                            <p>正品保障，提供发票</p>
                        </div>

                    </li>
                    <li class="grid-service-item intro intro5">

                        <i class="serivce-item fl"></i>
                        <div class="service-text">
                            <h4>正品保障</h4>
                            <p>正品保障，提供发票</p>
                        </div>

                    </li>
                </ul>
            </div>
            <div class="clearfix Mod-list">
                <div class="yui3-g">
                    <div class="yui3-u-1-6">
                        <h4>购物指南</h4>
                        <ul class="unstyled">
                            <li>购物流程</li>
                            <li>会员介绍</li>
                            <li>生活旅行/团购</li>
                            <li>常见问题</li>
                            <li>购物指南</li>
                        </ul>

                    </div>
                    <div class="yui3-u-1-6">
                        <h4>配送方式</h4>
                        <ul class="unstyled">
                            <li>上门自提</li>
                            <li>211限时达</li>
                            <li>配送服务查询</li>
                            <li>配送费收取标准</li>
                            <li>海外配送</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>支付方式</h4>
                        <ul class="unstyled">
                            <li>货到付款</li>
                            <li>在线支付</li>
                            <li>分期付款</li>
                            <li>邮局汇款</li>
                            <li>公司转账</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>售后服务</h4>
                        <ul class="unstyled">
                            <li>售后政策</li>
                            <li>价格保护</li>
                            <li>退款说明</li>
                            <li>返修/退换货</li>
                            <li>取消订单</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>特色服务</h4>
                        <ul class="unstyled">
                            <li>夺宝岛</li>
                            <li>DIY装机</li>
                            <li>延保服务</li>
                            <li>品优购E卡</li>
                            <li>品优购通信</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>帮助中心</h4>
                        <img src="${basePath}staticDwm/img/wx_cz.jpg">
                    </div>
                </div>
            </div>
            <div class="Mod-copyright">
                <ul class="helpLink">
                    <li>关于我们<span class="space"></span></li>
                    <li>联系我们<span class="space"></span></li>
                    <li>关于我们<span class="space"></span></li>
                    <li>商家入驻<span class="space"></span></li>
                    <li>营销中心<span class="space"></span></li>
                    <li>友情链接<span class="space"></span></li>
                    <li>关于我们<span class="space"></span></li>
                    <li>营销中心<span class="space"></span></li>
                    <li>友情链接<span class="space"></span></li>
                    <li>关于我们</li>
                </ul>
                <p>地址：北京市昌平区建材城西路金燕龙办公楼一层 邮编：100096 电话：400-618-4000 传真：010-82935100</p>
                <p>京ICP备08001421号京公网安备110108007702</p>
            </div>
        </div>
    </div>
</div>
<!--页面底部END-->

<script type="text/javascript" src="${basePath}staticDwm/js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript" src="${basePath}staticDwm/js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="${basePath}staticDwm/js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="${basePath}staticDwm/js/widget/nav.js"></script>
<script type="text/javascript" src="${basePath}staticDwm/js/widget/jie.js"></script>
</body>
<script type="text/javascript">
    function  jei(id) {
        if(id){
            let unma = document.getElementById(id+"2").value;
            $.get("${basePath}cart/jie?id="+id+"&unma="+unma, function (data) {
                document.getElementById(id+"2").value=data;
                document.getElementById(id+"3").innerHTML=parseInt(document.getElementById(id+"1").innerHTML)*data;
            });
        }
    }
    function jia(id) {
        if(id){
            let unma = document.getElementById(id+"2").value;
            if(unma==10){
                alert("亲 不好意思，一个订单只能订购10份");
            }else{
                $.get("${basePath}cart/jia?id="+id+"&unma="+unma, function (data) {
                    document.getElementById(id+"2").value=data;
                    document.getElementById(id+"3").innerHTML=parseInt(document.getElementById(id+"1").innerHTML)*data;
                });
            }
        }
    }

    function qxx() {
        $("input[name='qxx']").each(function () {
            if($(this).prop("checked")){
                <c:forEach items="${cartName}" var="cartName">
                    $("input[name='${cartName.catname}1']").each(function () {
                        $("input[name='${cartName.catname}1']").prop("checked",true);
                    });
                    qx('${cartName.catname}');
                </c:forEach>
            }else {
                <c:forEach items="${cartName}" var="cartName">
                    $("input[name='${cartName.catname}1']").each(function () {
                        $("input[name='${cartName.catname}1']").prop("checked",false);
                    });
                    qx('${cartName.catname}');
                </c:forEach>
            }
        });

    }
    function qx(namecat) {
        if(namecat){
            var namecat1=namecat+"1";
            $("input[name='"+namecat1+"']").each(function () {
                if($(this).prop("checked")){
                    $("input[name='"+namecat+"']").each(function () {
                        $(this).prop("checked",true);
                    });
                    Statistics();
                }else{
                    $("input[name='"+namecat+"']").each(function () {
                        $(this).prop("checked",false);
                    });
                    Statistics();
                }
            });
        }
    }

    function Statistics() {
        var and=0;
        var commodity=0;
        <c:forEach items="${cartName}" var="cartName">
            $("input[name='${cartName.catname}']").each(function () {
                if($(this).prop("checked")){
                    <c:forEach items="${carts}" var="carts">
                        if($(this).val()==${carts.id}){
                            and+=${carts.price}*${carts.number}
                            commodity++;
                            return;
                        }
                    </c:forEach>
                }
            });
        </c:forEach>
        document.getElementById("commodity").innerHTML=commodity;
        document.getElementById("and").innerHTML="￥"+and;
    }

    function addUpdate() {
        var arr=[];
        <c:forEach items="${cartName}" var="cartName">
        $("input[name='${cartName.catname}']").each(function () {
            if($(this).prop("checked")){
                arr.push($(this).val());
            }
        });
        </c:forEach>
        window.location.href="${basePath}cart/addUpdate?id="+arr+"&name=${user.username}";
    }

    function getOrderInfo() {
        if(document.getElementById("commodity").innerHTML!=0){
            var arr=[];
            <c:forEach items="${cartName}" var="cartName">
                $("input[name='${cartName.catname}']").each(function () {
                    if($(this).prop("checked")){
                        arr.push($(this).val());
                    }
                });
            </c:forEach>

            window.location.href="${basePath}getOrder/select?name=${user.username}&arr="+arr;
        }
    }
</script>
</html>
